﻿using ByteSite.API.Model;
using ByteSite.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web.Http;

namespace ByteSite.API.Controllers
{
    public class ArticleController : ApiController
    {
        // GET: api/Article
        public HttpResponseMessage Get()
        {

            int channel_id = DTRequest.GetQueryInt("channel_id");
            int category_id = DTRequest.GetQueryInt("category_id");
            int size = DTRequest.GetQueryInt("size",20);
            int page = DTRequest.GetQueryInt("page", 1);


            BLL.article bll = new BLL.article();
            int totalCount = 0;
            List<Entitys.article> list = bll.GetList(channel_id, category_id, size, page, x => true, "sort_id asc,add_time desc,id desc", out totalCount);

            var response = new ResponseMessage
            {
                code = 200,
                msg = "",
                data = new
                {
                    page = page,
                    size = size,
                    total_count = totalCount,
                    list = list
                }
            };

            var result = new HttpResponseMessage()
            {
                Content = new StringContent(JsonHelper2.ObjectToJSON(response), Encoding.UTF8, "application/json")
            };
            return result;
        }

        // GET: api/Article/5
        public HttpResponseMessage Get(int id)
        {
            var response = new ResponseMessage
            {
                code = 200,
                msg = "",
                data = "value"

            };
            var result = new HttpResponseMessage()
            {
                Content = new StringContent(JsonHelper2.ObjectToJSON(response), Encoding.UTF8, "application/json")
            };
            return result;
        }

        // POST: api/Article
        public HttpResponseMessage Update([FromBody] string value)
        {
            var response = new ResponseMessage
            {
                code = 200,
                msg = ""

            };
            var result = new HttpResponseMessage()
            {
                Content = new StringContent(JsonHelper2.ObjectToJSON(response), Encoding.UTF8, "application/json")
            };
            return result;
        }

    }
}
